﻿namespace com.crownpack
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    using com.crownpack.Extensions.ObjectExtensions;
    using com.crownpack.Extensions.StringExtensions;

    [Serializable]
    public class Customer
    {
        #region Constructors

        public Customer( )
        {
        }

        public Customer( Dictionary<string, string> value )
        {
            if ( value.ContainsKey( Layout.Address1 ) )
                Address1 = value[ Layout.Address1 ].TryTrim( );

            if ( value.ContainsKey( Layout.Branch ) )
                Branch = value[ Layout.Branch ].TryTrim( );

            if ( value.ContainsKey( Layout.BranchManager ) )
                BranchManager = value[ Layout.BranchManager ].TryTrim( );

            if ( value.ContainsKey( Layout.BranchName ) )
                BranchName = value[ Layout.BranchName ].TryTrim( );

            if ( value.ContainsKey( Layout.City ) )
                City = value[ Layout.City ].TryTrim( );

            if ( value.ContainsKey( Layout.DivisionCode ) )
                DivisionCode = value[ Layout.DivisionCode ].TryTrim( );

            if ( value.ContainsKey( Layout.GroupCode ) )
                GroupCode = value[ Layout.GroupCode ].TryTrim( );

            if ( value.ContainsKey( Layout.LocationName ) )
                LocationName = value[ Layout.LocationName ].TryTrim( );

            if ( value.ContainsKey( Layout.LocationNo ) )
                LocationNo = value[ Layout.LocationNo ].ToNullableInt32( );

            if ( value.ContainsKey( Layout.ManagerEMail ) )
                ManagerEMail = value[ Layout.ManagerEMail ].TryTrim( );

            if ( value.ContainsKey( Layout.NA_ManagerEmailAddress ) )
                NA_ManagerEmailAddress = value[ Layout.NA_ManagerEmailAddress ].TryTrim( );

            if ( value.ContainsKey( Layout.NA_ManagerName ) )
                NA_ManagerName = value[ Layout.NA_ManagerName ].TryTrim( );

            if ( value.ContainsKey( Layout.NA_ManagerNo ) )
                NA_ManagerNo = value[ Layout.NA_ManagerNo ].TryTrim( );

            if ( value.ContainsKey( Layout.NA_ManagerPhone ) )
                NA_ManagerPhone = value[ Layout.NA_ManagerPhone ].TryTrim( );

            if ( value.ContainsKey( Layout.ParentCustomerName ) )
                ParentCustomerName = value[ Layout.ParentCustomerName ].TryTrim( );

            if ( value.ContainsKey( Layout.ParentCustomerNo ) )
                ParentCustomerNo = value[ Layout.ParentCustomerNo ].ToNullableInt32( );

            if ( value.ContainsKey( Layout.Salesrep ) )
                Salesrep = value[ Layout.Salesrep ].TryTrim( );

            if ( value.ContainsKey( Layout.SalesrepEmailAddress ) )
                SalesrepEmailAddress = value[ Layout.SalesrepEmailAddress ].TryTrim( );

            if ( value.ContainsKey( Layout.SalesrepPhone ) )
                SalesrepPhone = value[ Layout.SalesrepPhone ].TryTrim( );

            if ( value.ContainsKey( Layout.SectorCode ) )
                SectorCode = value[ Layout.SectorCode ].TryTrim( );

            if ( value.ContainsKey( Layout.St ) )
                St = value[ Layout.St ].TryTrim( );

            if ( value.ContainsKey( Layout.Zip ) )
                Zip = value[ Layout.Zip ].TryTrim( );
        }

        #endregion Constructors

        #region Properties

        public string Address1
        {
            get;
            set;
        }

        public string Branch
        {
            get;
            set;
        }

        public string BranchManager
        {
            get;
            set;
        }

        public string BranchName
        {
            get;
            set;
        }

        public string City
        {
            get;
            set;
        }

        public string DivisionCode
        {
            get;
            set;
        }

        public string GroupCode
        {
            get;
            set;
        }

        public string LocationName
        {
            get;
            set;
        }

        public int? LocationNo
        {
            get;
            set;
        }

        public string ManagerEMail
        {
            get;
            set;
        }

        public string NA_ManagerEmailAddress
        {
            get;
            set;
        }

        public string NA_ManagerName
        {
            get;
            set;
        }

        public string NA_ManagerNo
        {
            get;
            set;
        }

        public string NA_ManagerPhone
        {
            get;
            set;
        }

        public string ParentCustomerName
        {
            get;
            set;
        }

        public int? ParentCustomerNo
        {
            get;
            set;
        }

        public string Salesrep
        {
            get;
            set;
        }

        public string SalesrepEmailAddress
        {
            get;
            set;
        }

        public string SalesrepName
        {
            get;
            set;
        }

        public string SalesrepPhone
        {
            get;
            set;
        }

        public string SectorCode
        {
            get;
            set;
        }

        public string St
        {
            get;
            set;
        }

        public string Zip
        {
            get;
            set;
        }

        #endregion Properties

        #region Methods

        public static Customer Deserialize( string xmlvalue )
        {
            return xmlvalue.HtmlDecode( ).DeserializeFromXml<Customer>( );
        }

        public string Serialize( )
        {
            return this.SerializeToXml<Customer>( ).HtmlEncode( );
        }

        #endregion Methods
    }
}